Repository navigation
fix(lab-ops-hub): validate and bound the /crawl request-body read (#7036) - #8705
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 42 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ec9d1b6e31
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| self.connection.settimeout(left) | ||
| chunk = self.rfile.read(min(remaining, _CRAWL_READ_CHUNK_BYTES)) |
There was a problem hiding this comment.
Use single-read chunks to enforce the absolute body deadline
If a client declares an in-cap body and keeps sending bytes less than 10 seconds apart, this call can block far beyond the intended deadline: self.rfile is a buffered reader whose read(n) repeatedly receives until all n bytes arrive, with the socket timeout applying separately to each underlying receive. Because the entire allowed body fits in one chunk, the loop cannot recheck the deadline while those bytes trickle in, leaving every subsequent request blocked on the single-threaded server for potentially days. Use read1() and recheck the absolute deadline between reads, as _fetch_crawl already does.
Useful? React with 👍 / 👎.
Closes #7036.
What
POST /crawlinpkgs/lab-ops-hub/container/app.pytrustedContent-Lengthoutright:int(header)fed straight intorfile.read(length)on a single-threadedHTTPServer. A negative length reads until EOF and an oversized one waits for a body that may never finish — either wedges every later request, and malformed values surfaced as the catch-all 502.do_POSTnow validates the header before reading a single byte: missing, non-integer, negative, or over-cap values get a prompt 400 JSON error naming the problem. The cap is the named constant_CRAWL_REQUEST_MAX_BODY_BYTES = 65_536(the payload is a small{"url": ...}object)._read_request_body: exactlylengthbytes under one absolute deadline (_CRAWL_REQUEST_READ_TIMEOUT_SECONDS = 10, mirroring_fetch_crawl's deadline style), with the socket timeout restored afterwards. A stalled in-cap body gets a 408 attempt and, either way, the handler returns so the server answers the next request.validate_crawl_url,_fetch_crawl, and the Worker's side are untouched.Tests
New
TestCrawlContentLengthinpkgs/lab-ops-hub/test/test_container_validate.pyruns the real Handler over a real socket (validator/fetcher stubbed at the module): negative, oversized, and non-numeric lengths and a missing header each get a prompt 400 with a followingGET /still answering; a stalled in-cap body times out (408) and the server recovers; the well-formed control still returns 200.Suite: 77 tests — the 6 new ones pass; the only failure is the pre-existing
test_returns_idn_hosts_in_alabel_formerror, reproduced identically on clean main with this environment's idna build (unrelated to this change).Task 11478, lane any-d.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.